<?php
class M_qin_history extends Cemvc_Db_MysqlDb{
  public $PrimaryKey='id';
  /*CEPHP会在要需要时查询主键，但主动设置主键可以使程序执行更快*/

  public function __construct()
  {
    parent::__construct();
  }

  /* insert a user when register */
  public function add($array)
  {
    return $this->insert(array("content_type" => $array["content_type"],
			       "content_id"   => $array["content_id"],
			       "content"      => $array["content"],
			       "operate_type" => $array["operate_type"],
			       "author_id"    => $array["author_id"],
			       "author_name"  => $array["author_name"]));
  }

  public function get($id)
  {
    return $this->where("id = $id")->fetchOne();
  }
  public function get_history_with_author($author_id)
  {
    return $this->where("author_id = $author_id")->orderBy("ts_created desc")
      ->limit(ITEM_COUNT_PER_PAGE)->fetchAll();
  }

  public function get_history_with_content($content_type, $content_id)
  {
    return $this->where(array("content_type = '$content_type'", "content_id = $content_id"))->limit(ITEM_COUNT_PER_PAGE)->fetchAll();
  }
}